package top.whysu.edevice.utils;

import cn.hutool.core.date.DateUtil;
import top.whysu.edevice.dto.generate.HeaderDTO;
import top.whysu.edevice.dto.generate.ResponseDTO;

/**
 * 返回DTO
 */
public class ResponseUtil {

    public static <T> ResponseDTO<T> getSuccessResponse(HeaderDTO header, T body) {
        final ResponseDTO<T> response = new ResponseDTO<>();
        header.setDateTime(DateUtil.now());
        response.setHeader(header);
        response.setBody(body);
        response.setResult(ResultUtil.getSuccessResult());
        return response;
    }

    public static <T> ResponseDTO<T> getSuccessResponse(HeaderDTO header) {
        final ResponseDTO<T> response = new ResponseDTO<>();
        header.setDateTime(DateUtil.now());
        response.setHeader(header);
        response.setBody(null);
        response.setResult(ResultUtil.getSuccessResult());
        return response;
    }

    public static <T> ResponseDTO<T> getSuccessResponse(T body) {
        final ResponseDTO<T> response = new ResponseDTO<>();
        response.setHeader(new HeaderDTO());
        response.setBody(body);
        response.setResult(ResultUtil.getSuccessResult());
        return response;
    }

    public static <T> ResponseDTO<T> getSuccessResponse() {
        final ResponseDTO<T> response = new ResponseDTO<>();
        HeaderDTO header = new HeaderDTO();
        header.setDateTime(DateUtil.now());
        response.setHeader(header);
        response.setBody(null);
        response.setResult(ResultUtil.getSuccessResult());
        return response;
    }

    public static <T> ResponseDTO<T> getFailResponse(HeaderDTO header, Integer code, String msg) {
        final ResponseDTO<T> response = new ResponseDTO<>();
        header.setDateTime(DateUtil.now());
        response.setHeader(header);
        response.setResult(ResultUtil.getFailedResult(code, msg));
        return response;
    }
}
